const qs = require('querystring');

const bodyparser = (ctx)=> {
    return new Promise((resolve,reject) => {
        let bufStr = '';
        ctx.req.on('data',chunk => {
            bufStr += chunk;
        })

        ctx.req.on('end',() => {
            resolve(qs.parse(bufStr));
        })
    })
}
module.exports = () => {
    return async (ctx,next) => {
         if(ctx.request.method === 'POST'){
            ctx.request.body = await bodyparser(ctx);
            await next()
        }else{
            await next()
        }
    }
}